﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BesAsm.Framework.CommonControls
{
  /// <summary>
  /// A modal dialog which provides a multiline text input form. Includes an optional dropdown list which is not visible by default,  
  /// </summary>
  public partial class TextInputDialog : Form
  {
    private bool _lastEntryItemsVisible = false;

    protected TextInputDialog()
    {
      InitializeComponent();
      lblItems.Visible = false;
      cmbItems.Visible = false;
      cmbLastEntry.Visible = false;
      lblLastEntryItems.Visible = false;
      DropDownItemDefaultIndex = 0;
    }

    /// <summary>
    /// Construct a new TextInputDialog
    /// </summary>
    /// <param name="caption">The caption to be shown in the title bar</param>
    /// <param name="message">The message to be shown above the input box</param>
    public TextInputDialog(string caption, string message)
      : this()
    {
      Text = caption;
      lblMessage.Text = message;
    }    

    /// <summary>
    /// The caption shown above the title bar
    /// </summary>
    public string Caption
    {
      get { return base.Text; }
      set { base.Text = value; }
    }

    /// <summary>
    /// The message shown above the input box
    /// </summary>
    public string Message
    {
      get { return lblMessage.Text; }
      set { lblMessage.Text = value; }
    }

    /// <summary>
    /// Gets or sets the text in the input box
    /// </summary>
    public string InputText
    {
      get { return txtInput.Text; }
      set { txtInput.Text = value; }
    }

    /// <summary>
    /// Gets or sets whether the control uses multiline input. Default is true.
    /// </summary>
    public bool IsMultiline
    {
      get { return txtInput.Multiline; }
      set { txtInput.Multiline = value; }
    }

    /// <summary>
    /// Gets or sets the text to show in the OK button
    /// </summary>
    public string OkText
    {
      get { return btnOk.Text; }
      set { btnOk.Text = value; }
    }

    /// <summary>
    /// Gets or sets the text to show in the Cancel button
    /// </summary>
    public string CancelText
    {
      get { return btnCancel.Text; }
      set { btnCancel.Text = value; }
    }

    public string DropDownLabelText
    {
      get { return lblItems.Text; }
      set { lblItems.Text = value; }
    }

    public string[] DropDownItems
    {
      get { return (string[])cmbItems.DataSource; }
      set { cmbItems.DataSource = value; }
    }

    public int DropDownItemDefaultIndex
    {
      get;
      set;
    }

    public string SelectedDropDownItem
    {
      get { return cmbItems.Value as string; }
    }

    public bool UseDownDown
    {
      get { return lblItems.Visible; }
      set
      {
        lblItems.Visible = value;
        cmbItems.Visible = value;
      }
    }

    public bool LastEntryItemsVisible
    {
      get { return _lastEntryItemsVisible; }
      set
      {
        _lastEntryItemsVisible = value;
        cmbLastEntry.Visible = _lastEntryItemsVisible;
        lblLastEntryItems.Visible = _lastEntryItemsVisible;
      }
    }

    public string[] LastEntryItems
    {
      get { return (string[])cmbLastEntry.DataSource; }
      set { cmbLastEntry.DataSource = value; }
    }

    /// <summary>
    /// Sets the number of rows visible in the input box without requiring a scroll bar
    /// </summary>
    public int VisibleRowCount
    {
      get { return txtInput.Font.Height / txtInput.Height; }
      set { txtInput.Height = txtInput.Font.Height * value; }
    }
  }
}
